/*
 * cudanBaseMemory.h
 *
 *  Created on: Dec 8, 2009
 *      Author: daniel
 */

#ifndef CUDANBASEMEMORY_H
#define CUDANBASEMEMORY_H

#include <iostream>
#include <vector>

namespace CUDAN
{
	template<typename T, int D> class HostMemory;
	template<typename T, int D> class DeviceMemory;

	// Specifies the size of each dimension as a vector.
	typedef std::vector<int> DimensionSizeVector;

	// Defines an abstract base class for each memory type.
	template<typename T, int D = 1>
	class BaseMemory
	{
	public:
		// Pointer to memory.
		T* memory;

		// Size of each dimension.
		DimensionSizeVector sizeDim;

		// Number of elements in memory. Not in physical memory ie bytes.
		size_t size;

	public:
		BaseMemory();
		virtual ~BaseMemory() {};

	protected:
		int getSize(DimensionSizeVector&);

	public:
		virtual int getIndex(DimensionSizeVector&);
		virtual __host__ int getIndex(int[D]);
		virtual void freeMemory() = 0;
		virtual void print() = 0;
		virtual void print(DimensionSizeVector&) = 0;
		virtual bool allocateMemory(DimensionSizeVector&) = 0;
		virtual bool copyFrom(HostMemory<T,D>*) = 0;
		virtual bool copyFrom(DeviceMemory<T,D>*) = 0;
		virtual bool copyTo(HostMemory<T,D>*) = 0;
		virtual bool copyTo(DeviceMemory<T,D>*) = 0;
	};
}

#include "cudanBaseMemory.cpp"

#endif /* CUDAFWBASEMEMORY_H_ */
